﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Manger_ResourceList : System.Web.UI.Page
{
    string sMajorID;
    string sMajorName;
    protected void Page_Load(object sender, EventArgs e)
    {

        HttpCookie ck = Request.Cookies["major"];
        if (ck != null)
        {
            sMajorID = ck.Values["majorid"];
            sMajorName = HttpUtility.UrlDecode(ck.Values["majorname"]);
            XmlDataSource1.DataFile = "~/xml/ResourceType_" + sMajorID + ".xml";


            if (!IsPostBack)
            {
                SqlDataSource1.SelectCommand = "SELECT [Resource_ID],[Resource_TypeName], [Resource_Name], [Resource_Size], [Resource_AddDate] FROM [zyk_Resources]";
                SqlDataSource1.SelectCommand += " where  [Resource_MajorID]=@majorid order by [Resource_AddDate] desc";
                SqlDataSource1.SelectParameters.Clear();
                SqlDataSource1.SelectParameters.Add("majorid", Request.Cookies["major"].Values["majorid"]);
            }
        }
        else
        {
            FormsAuthentication.SignOut();
            FormsAuthentication.RedirectToLoginPage();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        TreeView1.Visible = true;
    }
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
    {
        TreeView1.Visible = false;
        SqlDataSource1.SelectCommand = "SELECT [Resource_ID],[Resource_TypeName], [Resource_Name], [Resource_Size], [Resource_AddDate] FROM [zyk_Resources]";
        SqlDataSource1.SelectCommand += " where  [Rescource_MajorID]=@majorid and Resource_Type=@type order by [Resource_AddDate] desc";
        SqlDataSource1.SelectParameters.Clear();
        SqlDataSource1.SelectParameters.Add("type", TreeView1.SelectedNode.Value);
        SqlDataSource1.SelectParameters.Add("majorid", Request.Cookies["major"].Values["majorid"]);
        SqlDataSource1.Select(DataSourceSelectArguments.Empty);
        GridView1.DataBind();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        SqlDataSource1.SelectCommand = "SELECT [Resource_ID],[Resource_TypeName], [Resource_Name], [Resource_Size], [Resource_AddDate] FROM [zyk_Resources]";
        SqlDataSource1.SelectCommand += " where  [Rescource_Name] like '%'+@name+'%' order by [Resource_AddDate] desc";
        SqlDataSource1.SelectParameters.Clear();
        SqlDataSource1.SelectParameters.Add("name", tbKeyWord.Text);
        SqlDataSource1.Select(DataSourceSelectArguments.Empty);
        GridView1.DataBind();
    }
    protected void GridView1_RowDeleted(object sender, GridViewDeletedEventArgs e)
    {

        SqlDataSource1.SelectCommand = "SELECT [Resource_ID],[Resource_TypeName], [Resource_Name], [Resource_Size], [Resource_AddDate] FROM [zyk_Resources]";
        SqlDataSource1.SelectCommand += " where  [Resource_MajorID]=@majorid  order by [Resource_AddDate] desc";
        SqlDataSource1.SelectParameters.Clear();
        SqlDataSource1.SelectParameters.Add("majorid", Request.Cookies["major"].Values["majorid"]);
        GridView1.DataBind();
       
    }
}
